<?php
	
?>
<div class="formList goc5" style="border: 1px solid #efefef;">
	<div class="appTop goct5">
		<div class="block_filter">
			<div class="fl">
				<div class="listSearch">
					<span class="title">Danh sách khách hàng</span>
					<div class="clr"></div>			
				</div>
			</div>
			<div class="fr">
				<div class="listSelect" style="padding: 3px 5px 0 0;">
					<span>Đã chọn: </span><span id="daChon">0</span>/<span id="tongSoKH">0</span> <span>(Tối đa: 10.000 Khách hàng)</span>
				</div>
				<script type="text/javascript">
					$(document).ready(function(){
						tongKhachhang();
						demDaChon();
						$('#tblKhachHang #checkbox').click(function(){
							demDaChon();
						});
						$('#tblKhachHang tr #cid').click(function(){
							demDaChon();
						});
					});

					function tongKhachhang() {
						var tongSoKH = $('#tblKhachHang tr').size() - 1;
						$('#tongSoKH').text(tongSoKH);
					}
					function demDaChon(){
						var daChon = 0;
						$('#tblKhachHang tr #cid').each(function(index){
							if($(this).is(':checked')){
								daChon++;
							}
						});
						daChon += $('a#dachon').size();
						$('#daChon').text(daChon);
					}

					function xoaXml(id, id_xoa) {
						if(confirm('Nếu xóa sẽ không thể lấy lại. Bạn có muốn xóa thật không?')){
							var url = '<?php echo $this->baseUrl('marketing/ajax/xoa-xml');?>';
							$.ajax({
						      	url: url,
						      	type: 'POST',
						      	dataType: 'html',
						      	data: {file_name : id, id : id_xoa},
						      	beforeSend: function(){
									$('td#' + id_xoa).html('');
									$('td#' + id_xoa).addClass('dangtai');
							 	},
						      	success: function(html){
						      		$('#tblKhachHang tr#' + id_xoa).remove();
						      		tongKhachhang();
							    }
						   	});
						}
					}

					function trangthaiXml(id, id_xoa, item) {
						var valItem = $(item).val();
						var url = '<?php echo $this->baseUrl('marketing/ajax/trangthai-xml');?>';
						$.ajax({
					      	url: url,
					      	type: 'POST',
					      	dataType: 'html',
					      	data: {file_name : id, id : id_xoa, trangthai : valItem},
					      	beforeSend: function(){
					      		$('body').append('<div class="loading_page"></div>');
						 	},
					      	success: function(html){
					      		$('.loading_page').remove();
						    }
					   	});
					}
				</script>
			</div>
			<div class="clr"></div>
		</div>
	</div>
	<div class="appBody">
		<table class="tblList" id="tblKhachHang">
			<tr>
				<th width="20"><input type="checkbox" name="checkbox" id="checkbox" onclick="checkedAll()"></th>
				<th>Họ tên</th>
				<th width="100">Điện thoại</th>
				<th width="180">Email</th>
				<th>Khóa học</th>
				<th width="80">Trạng thái</th>
			</tr>
			<?php
			$khachhang = array();
			if(!empty($this->arrParam['khachhang'])) {
				$khachhang = $this->arrParam['khachhang'];
			}
			foreach ($this->Items AS $key => $val) {
				$id 			= $val['id'];
				$name 			= $val['name'];
				$phone 			= $val['phone'];
				if($val['phone'] == '') {
					$phone		= $val['telephone'];
				}
				$email 			= $val['email'];
				$khoahoc_name	= $val['khoahoc_name'];
				$trangthai		= '';
				$cid 			= $this->formCheckbox('cid[]',$val['id']);
				if(!empty($this->arrParam['cid'])){
					if (in_array($val['id'], $this->arrParam['cid'])) {
						$cid 			= $this->formCheckbox('cid[]', $val['id'], array('checked' => 'checked'));
					} 
				}
				if(!empty($khachhang[$val['id']])) {
					$cid		= '<a href="javascript:void(0)" onclick="xoaXml('.$this->arrParam['id'].','.$val['id'].')" id="dachon">[Xóa]</a>';
					$trangthai	= $this->formSelect('trangthai',$khachhang[$val['id']]['trangthai'],array('onchange' => 'trangthaiXml('.$this->arrParam['id'].','.$val['id'].',this)'), $this->Trangthai);
				}
				
				$classRow = 'row1';
				if($key % 2 == 0)
					$classRow = '';
			?>
			<tr class="<?php echo $classRow;?>" id="<?php echo $id;?>">
				<td align="center" id="<?php echo $id;?>">
					<?php echo $cid;?>
					<input type="hidden" name="id_chon[]" value="<?php echo $id;?>">
				</td>
				<td align="left"><span style="color: #0051A4;"><?php echo $name;?></span></td>
				<td align="left"><?php echo $phone;?></td>
				<td align="left"><?php echo $email;?></td>
				<td align="left"><?php echo $khoahoc_name;?></td>
				<td align="center"><?php echo $trangthai;?></td>
			</tr>
			<?php
			} 
			?>
		</table>
	</div>
</div>
